package com.xywy.start;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.xywy.R;
import com.xywy.common.BaseActivity;
import com.xywy.common.widget.TitleBar;

/**
 * 你的性别
 * 
 * @author xiaogd
 * 
 */
public class SexActivity extends BaseActivity {
	private static final String TAG = "SexActivity";
	private static final String MALE = "male";
	private static final String FEMALE = "female";

	private ImageView ivMale;
	private ImageView ivFeMale;
	private TextView tvBack;
	private Button sex_next;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 设置为全屏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.start_sex);
		this.preInit();
		this.initView();
	}

	@Override
	public void initView() {
		// title
		TitleBar titleBar = (TitleBar) findViewById(R.id.title_bar);
		TextView tvTitle = titleBar.getTitle();
		tvBack = titleBar.getTvBack();
		titleBar.onClickBack(this);
		tvTitle.setText(getString(R.string.tv_start_sex));

		ivMale = (ImageView) findViewById(R.id.iv_sex_male);
		ivFeMale = (ImageView) findViewById(R.id.iv_sex_female);
		sex_next = (Button) findViewById(R.id.bt_sex_next);
	}

	public void onSexClick(View view) {
		switch (view.getId()) {
		case R.id.bt_sex_next:
			next();
			break;
		case R.id.iv_sex_male:
			changeSex(MALE);
			sex_next.setBackground(getResources().getDrawable(
					R.drawable.shape_button));
			sex_next.setClickable(true);
			break;
		case R.id.iv_sex_female:
			changeSex(FEMALE);
			sex_next.setBackground(getResources().getDrawable(
					R.drawable.shape_button));
			sex_next.setClickable(true);
			break;
		}
		;
	}

	int sex = 1;

	/**
	 * 切换 选项
	 * 
	 * @param chStr
	 */
	private void changeSex(String chStr) {
		int maleDraw = R.drawable.start_sex_male;// start_sex_male_selected
		int femaleDraw = R.drawable.start_sex_female;
		if (chStr.equals(FEMALE)) {
			sex = 2;
			maleDraw = R.drawable.start_sex_male;
			femaleDraw = R.drawable.start_sex_female_selected;
		} else if (chStr.equals(MALE)) {
			sex = 1;
			maleDraw = R.drawable.start_sex_male_selected;
			femaleDraw = R.drawable.start_sex_female;
		}
		ivMale.setBackgroundDrawable(getResources().getDrawable(maleDraw));
		ivFeMale.setBackgroundDrawable(getResources().getDrawable(femaleDraw));
	}

	int height = 0;

	private void next() {
		Intent intent = new Intent(this, BirthActivity.class);
		String userid = this.getIntent().getStringExtra("userid");
		if (userid != null) {
			intent.putExtra("userid", userid);
		}
		intent.putExtra("sex", sex);
		intent.putExtra("height", height);
		startActivity(intent);
	}

	@Override
	public void preInit() {
		Intent intent = this.getIntent();
		height = intent.getIntExtra("height", 0);
	}

	@Override
	public void loadData() {

	}

	@Override
	public void onBackPressed() {
		this.finish();
		super.onBackPressed();
	}

}
